#
# This program generates a PNG image file which represents the 
# data on execution time stored in the given file whose name is passed
# as argument.
#
# Usage:
# R --slave --args source_filename image_filename < grain_size_speedup.r
# 
# Arguments:
# source_filename: the file that stores the data
# image_filename: name of the generated image file
#

#
# Required libraries
#
library(ggplot2)

#
# Generated image properties
#
width = 1000
height = 1000
res = 120

args <- commandArgs()
source_file <- args[4]
generated_image_name <- args[5]

#
# Loading data
#

print("passou")
times <- read.csv(source_file, sep=" ")

# this line is necessary because the columns can have any name
colnames(times) <- c('X0', 'X1')
speedups <- c(rep.int(times$X1[1],length(times$X0)))/times$X1
print(times)
print(c(rep.int(times$X1[1],length(times$X0))))
print(speedups)
print(times$X0)

frame <- data.frame(time = times$X0[2:length(times$X0)], 
		    times = speedups[2:length(times$X0)])

plot <- ggplot(height = height, width = width, res = res, frame, aes(frame$time, frame$times))

# Setting image properties
png(generated_image_name, height = height, width = width, res = res)

plot + 
# horizontal axis
scale_x_continuous(name="tamanho do grão") + 
# vertical axis
scale_y_continuous("speedup") + 
# use color
geom_line(aes(colour = frame$times)) + 
# title
opts(title = expression("tamanho do grão X speedup"))
